package ev.operator;//need to add this line

import java.util.Random;

public class MidCycle implements Crossover{
	public int[] cross(int[] a, int[] b){
		Random r=new Random();
		int t;
		int position1=r.nextInt(a.length);
		int position2=r.nextInt(a.length);
		while(position1==position2){
			position2=r.nextInt(a.length);
		}
		if(position1>position2){
			t=position1;
			position1=position2;
			position2=t;
		}
		int temp;
		for(int i=position1;i<=position2;i++){
			temp=a[i];
			a[i]=b[i];
			b[i]=temp;
		}
		return a;
	}
		
	public	boolean[] cross(boolean[] a, boolean[] b){		
		Random r=new Random();
		int t;
		int position1=r.nextInt(a.length);
		int position2=r.nextInt(a.length);
		while(position1==position2){
			position2=r.nextInt(a.length);
		}
		if(position1>position2){
			t=position1;
			position1=position2;
			position2=t;
		}
		boolean temp;
		for(int i=position1;i<=position2;i++){
			temp=a[i];
			a[i]=b[i];
			b[i]=temp;
		}
		return a;
	}
	
}
